package com.cxf.cxfzuul.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.cxf.cxfzuul.repository.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * description: TokenUtils <br>
 * date: 2021/11/3 21:09 <br>
 * author: cxf <br>
 * version: 1.0 <br>
 */
@Component
public class TokenUtils {


    private static final Logger logger = LoggerFactory.getLogger(TokenUtils.class);

    public String getToken(User user) {
        String token="";
        token= JWT.create().withAudience(user.getId())
                .sign(Algorithm.HMAC256(user.getPassword()));

        logger.info(user.toString()+" 生成的token is "+token);
        return token;
    }

}
